//
//  YXFlutterBoostManager.m
//  flutter_yuanxin_Example
//
//  Created by GMS on 2020/10/19.
//  Copyright © 2020 Arthur. All rights reserved.
//

#import "YXFlutterBoostManager.h"
#import <flutter_boost/FlutterBoost.h>

@implementation YXFlutterBoostManager

+ (void)pushWithRoute:(NSString *)route andVC:(UIViewController *)vc {
    
    [self pushWithRoute:route VC:vc andParams:@{}];
}

+ (void)pushWithRoute:(NSString *)route VC:(UIViewController *)vc andParams:(NSDictionary *)params {
    
    //
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"language":@"en-us",@"token":@"eyJhbGciOiJIUzI1NiIsInppcCI6IkRFRiJ9.eNoky9EKgzAMheF3ybWBtKZJ48uM1lboYJtMBWHs3VfZ5fn4zwe2I8METsU7Yj8SwQDHVt-3VrqTWJYlMNboBHn2FZP3hIFzWcgiG1-HbX6tteepPNqz73quMDmhUYxVdYCW9j9QNLvgvrfeS1IrViLWMRmyhoBJKWAWdUqUCwvD9wcAAP__.-6H6n_ZG13OcP1z-9ehu65LQHs8awVs2foyQaKqxBmU"}];
    
    // 合并两个字典
    [dic addEntriesFromDictionary:params];
    
    __weak __typeof(UIViewController *)weakVC = vc;

    [FlutterBoostPlugin open:route urlParams:dic exts:@{@"animated":@(YES),@"vc":weakVC,@"type":@"push"} onPageFinished:^(NSDictionary * result) {

        NSLog(@"返回结果 %@",result);

    } completion:^(BOOL finish) {
        NSLog(@"push页面结束");
    }];
    
}

// MARK: present页面
+ (void)presentWithRoute:(NSString *)route andVC:(UIViewController *)vc {
    
    [self presentWithRoute:route VC:vc andParams:@{}];
}

// MARK: 有参数的present页面
+ (void)presentWithRoute:(NSString *)route VC:(UIViewController *)vc andParams:(NSDictionary *)params {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"language":@"en-us",@"token":@"eyJhbGciOiJIUzI1NiIsInppcCI6IkRFRiJ9.eNoky9EKgzAMheF3ybWBtKZJ48uM1lboYJtMBWHs3VfZ5fn4zwe2I8METsU7Yj8SwQDHVt-3VrqTWJYlMNboBHn2FZP3hIFzWcgiG1-HbX6tteepPNqz73quMDmhUYxVdYCW9j9QNLvgvrfeS1IrViLWMRmyhoBJKWAWdUqUCwvD9wcAAP__.-6H6n_ZG13OcP1z-9ehu65LQHs8awVs2foyQaKqxBmU"}];
    
    // 合并两个字典
    [dic addEntriesFromDictionary:params];
    
    __weak __typeof(UIViewController *)weakVC = vc;

    [FlutterBoostPlugin present:route urlParams:dic exts:@{@"animated":@(YES),@"vc":weakVC,@"type":@"push"} onPageFinished:^(NSDictionary * result) {

        NSLog(@"返回结果 %@",result);

    } completion:^(BOOL finish) {
        NSLog(@"页面结束");
    }];
    
}



@end
